package HomeWork;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
/*	5. hashmap去做
合并 输出数组两个数组中都有元素则去除
[1,2,3]
[3,4,5,2]
得到[1,4,5]*/
public class work05 {
    public static void main(String[] args) {
        int[] arr1 = {1, 2, 3};
        int[] arr2 = {3, 4, 5, 2};

        HashMap<Integer, Integer> map = new HashMap<>();
        ArrayList<Integer> result = new ArrayList<>();

        for (int num : arr1) {
            map.put(num, 1);
        }

        for (int num : arr2) {
            if (map.containsKey(num)) {
                map.remove(num);
            } else {
                result.add(num);
            }
        }

        for (int key : map.keySet()) {
            result.add(key);
        }

        Collections.sort(result);
        System.out.println("合并去重后的数组：");
        System.out.println(result);
    }
}
